//
//  ZJUserAccount.swift
//  Webo
//
//  Created by 曾静 on 16/6/26.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit

//只能放在这个里面,不然接档不能放在类的扩展里面
class ZJUserAccount: NSObject,NSCoding {

    var access_token:String?
    
    //创建一个NSDate的时间方便计算
    var expires_Data : NSDate?
    
    var expires_in: NSTimeInterval = 0{
        
        didSet{
            
            expires_Data = NSDate(timeIntervalSinceNow: expires_in)
            
            print(expires_Data)
        }

    }
    
   
    var uid:String?
    
    var avatar_large:String?
    
    var screen_name:String?
    
    init(dict:[String:AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
        
    override var description: String{
        let keys = ["access_token", "expires_Data", "uid", "avatar_large", "screen_name"]
        return dictionaryWithValuesForKeys(keys).description
    }
    
    
    
    //归档
    func encodeWithCoder(aCoder: NSCoder) {
        
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(expires_Data, forKey: "expires_Data")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(screen_name, forKey: "screen_name")

    }
    
    //接档
    
    required init?(coder aDecoder: NSCoder) {
        
        access_token = aDecoder.decodeObjectForKey("access_token")as?String
        expires_Data = aDecoder.decodeObjectForKey("expires_Data") as?NSDate
        
        uid = aDecoder.decodeObjectForKey("uid") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
        
    }
    
}

    

